package com.example.mouther_bg.service.Impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mouther_bg.Bean.Video;
import com.example.mouther_bg.Mapper.VideoMapper;
import com.example.mouther_bg.service.videoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@Service
public  class voideServiceImpl extends ServiceImpl<VideoMapper, Video> implements videoService {
    @Autowired
    private VideoMapper videoMapper;
//    @Override
//    public String updateVideo(MultipartFile file) throws IOException {
//        String fileName =  file.getOriginalFilename();
//        String title = fileName.substring(0,fileName.lastIndexOf("."));
//            String ACCESS_KEY_ID ="LTAI5tEqhMw9VP83Rm9xb54d";
//            String ACCESS_KEY_KEYSECTET ="vbgDlknODJSy4wggHvkTEGDzKo33TG";
//        InputStream inputStream = file.getInputStream();
//        UploadStreamRequest request = new UploadStreamRequest(ACCESS_KEY_ID,ACCESS_KEY_KEYSECTET, title, fileName,inputStream);
//        UploadVideoImpl uploader = new UploadVideoImpl();
//        UploadStreamResponse response = uploader.uploadStream(request);
//            String videoId = null;
//            if (response.isSuccess()) {
//                videoId = response.getVideoId();
//            } else {
//                /* 如果设置回调URL无效，不影响视频上传，可以返回VideoId同时会返回错误码。其他情况上传失败时，VideoId为空，此时需要根据返回错误码分析具体错误原因 */
//                System.out.print("VideoId=" + response.getVideoId() + "\n");
//                System.out.print("ErrorCode=" + response.getCode() + "\n");
//                System.out.print("ErrorMessage=" + response.getMessage() + "\n");
//                videoId = response.getVideoId();
//            }
//        return videoId;
//    }

    @Override
    public List<Video> listAll() {
        List<Video> videos = videoMapper.listAll();
        return videos;
    }

    @Override
    public Video getOneById(int id) {
        return videoMapper.getOneById(id);
    }

    @Override
    public List<Video> queryKeyVideo(String videoContent) {
        return videoMapper.queryKeyVideo(videoContent);
    }

    @Override
    public List<Video> queryVideoByUserId(int id) {
        List<Video> videos = videoMapper.queryVideoByUserId(id);
        return videos;
    }

    @Override
    public List<Video> pageQuery(Integer page, Integer perPage) {
        List<Video> videos = videoMapper.pageQuery(page, perPage);
        System.out.println(videos);
        return videos;
    }

    @Override
    public int queryAllCount() {
        return videoMapper.queryAllCount();
    }


}
